using UnityEngine;

/// <summary>
/// 人物角色属性
/// </summary>
public class state : MonoBehaviour
{
    /// <summary>
    /// 生命值
    /// </summary>
    public float health;
    /// <summary>
    /// 攻击力
    /// </summary>
    public float ATK;
    /// <summary>
    /// 气值，用于放绝招
    /// </summary>
    public float energy;

    public float runSpeed = 8f;
    /// <summary>
    /// 是否可以移动
    /// </summary>
    public bool isMovable = true;
    /// <summary>
    /// 是否无敌
    /// </summary>
    public bool isInvincible = false;
    /// <summary>
    /// 当前是否为硬直状态，硬直状态下释放技能不会被打断，即使受伤也不会被打断
    /// </summary>
    public bool isStiff = false;
    //当前是否在传送门接触范围内
    public bool isInTransDoor = false;
    /// <summary>
    /// 在梯子上
    /// </summary>
    public bool isOnLadder = false;
    /// <summary>
    /// 是否可以爬梯子
    /// </summary>
    public bool canClimb = true;
    /// <summary>
    /// 是否可以跳跃
    /// </summary>
    public bool isJumpable = true;
    /// <summary>
    /// 多段跳最大跳数,为1则没有多段跳
    /// </summary>
    public int maxMultiJump = 1;
    /// <summary>
    /// 当前角色还能在空中跳几次
    /// </summary>
    public int currentJumpCnt;

    public enum MovementState
    {
        /// 当前是否正在释放技能，同一时刻只能释放一个技能
        PLAY_SKILL,
        /// 是否正在走路
        WALKING,
        /// 是否正在跑步
        RUNNING,
        /// <summary>
        /// 正在攀爬
        /// </summary>
        CLIMBING,
        /// <summary>
        /// 空闲状态
        /// </summary>
        IDLE,
        /// <summary>
        /// 受击
        /// </summary>
        HURTING,
        /// <summary>
        /// 浮空状态
        /// </summary>
        FLOATING,
        /// <summary>
        /// 死亡
        /// </summary>
        DEAD,
    }
    /// <summary>
    /// 角色运动状态机
    /// todo:可能需要改进
    /// </summary>
    public MovementState movementState = MovementState.IDLE;

    // Start is called before the first frame update
    private void Awake()
    {
        currentJumpCnt = maxMultiJump;
    }
    void Start()
    {
        movementState = MovementState.IDLE;
    }

    // Update is called once per frame
    void Update()
    {
        //检查血量,死亡条件
        if (health < 0 && !isInvincible)
        {
            Destroy(this.gameObject);
        }

    }
    /// <summary>
    /// 设置角色移动速度
    /// </summary>
    /// <param name="speed"></param>
    public void setRunSpeed(float speed)
    {
        if (speed <= 0)
        {
            speed = 1;
        }
        else
        {
            runSpeed = speed;
        }
    }
    /// <summary>
    /// 重置角色多段跳剩余次数
    /// </summary>
    public void resetMultiJumpCnt()
    {
        currentJumpCnt = maxMultiJump;
    }
}
